home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
mcomm
/
txzm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-02
|
58KB
|
1,666 lines
/*/////////////////////////////////////////////////////////////////////
// //
// TXZM.C -- zmodem protocol driver (formerly ZMP) //
// //
// (c) 1991-94, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503 //
// //
//////////////////////////////////////////////////////////////////// */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <process.h>
#include <ctype.h>
#include <io.h>
#include <dos.h>
#include <bios.h>
#include "comm.h"
#include "ansidrv.h"
#include "extra.h"
#include "colors.h"
#include "zmdos.h"
#if defined (__TURBOC__)
#include <dir.h>
#define ChDrive(d) setdisk((d)-1)
#pragma warn -par
#ifdef _RTLENTRY // BC4 or greater
#pragma option -x- -RT-
void _ExceptInit(void) {} // disable exception handling
#endif
#elif defined (__ZTC__)
#include <direct.h>
#define ChDrive(d) _chdrive(d)
#elif defined (__MSC__)
int ndrives;
#define ChDrive(d) _dos_setdrive((d), &ndrives)
#endif
#define ALT_C 0x2e00
#define ALT_D 0x2000
#define ALT_E 0x1200
#define ALT_H 0x2300
#define ALT_L 0x2600
#define ALT_P 0x1900
#define ALT_R 0x1300
#define ALT_S 0x1f00
#define ALT_X 0x2d00
#define FK1 0x3b00
#define PGUP 0x4900
#define PGDN 0x5100
#define ALT_EQU 0x8300
#define X_ESC 0x011b
void AddToList(char *subdir);
char *CaptureBaudRate(void);
char *ConvertSecs(long secs);
int Dial(void);
void DrawBox(int row, int col, int nrows, int ncols, int color, int style);
void DspZmodemScrn(void);
char *ExpandSubDirs(char *fnames);
int FileTransfer(void);
int GetNumber(void);
long getHunds(void);
long getSeconds(void);
void HelpFunc(void);
void InitDefaults(void);
void MiniTermMode(void);
void ProcCmdLine(int argc, char * *argv);
int prompt(char *buf, int maxlen);
void ReadDialDir(void);
int RecurseSubDirs(char *sd);
int RepeatDial(void);
void SetFIFOLevels(int rxFIFOlevel, int txFIFOlevel);
int SetParams(char *newparams);
void usage(void);
void vDisplay(int row, int col, char *format, ...);
int waitfor(int ticks, ...);
void ZMsg(int type, ...);
extern int _C_ TestDesqView(void);
extern int _C_ DV_VideoSeg(int);
extern void _C_ DV_TimeSlice(void);
/*/////////////////////////////////////////////////////////
// Configuration structure. Structure is used to allow //
// the defaults to be changed modifying the EXE. //
// "TXZMCFG:" is the tag to search for to find the start//
// of the structure in the EXE. //
//////////////////////////////////////////////////////// */
struct PROTCONFIG
{
char tag[8], DLPath[80], ULPath[80];
long LocBaud, MinFifoBaud;
int ComBase, IRQ, Vctr;
int h_VBufSize, h_BufSize, b_VBufSize, b_BufSize;
int TxWindow, ZExistOpts, XYExistOpts;
int FifoTxLvl, FifoRxLvl;
char IgnCarrier, MsrFlow, KeepTime, EscCtl, OvlyIO;
char Color[10], Mono[10];
} cfg =
{
"TXZMCFG:", "", "",
0L, 1L,
0x3f8, IRQ4, VCTR4,
2048, 0, 20508, 20480,
0, 1, 2,
8, 8,
0, 0, 1, 0, 1,
{ WHT|BLU_B, H_GRN|BLU_B, H_RED|BLU_B, YLW|BLU_B,
GRY|BLU_B, YLW|BLU_B, H_RED|BLU_B, H_MAG|BLU_B,
CYN, CYN_B },
{ WHT, WHT, RVRS, H_WHT, WHT, H_WHT, H_WHT, H_WHT, WHT, WHT_B }
};
/*/////////////////////////////////////////////////////////
// Screen data structure //
//////////////////////////////////////////////////////// */
typedef struct
{
int row, col, color, count;
char *text;
} SCREENDATA;
/*/////////////////////////////////////////////////////////
// Dial directory structure //
//////////////////////////////////////////////////////// */
static struct DIAL_DIRECTORY
{
char *num;
char *name;
} DialDir[10];
/*/////////////////////////////////////////////////////////
// Global variables //
//////////////////////////////////////////////////////// */
ASYNC port; /* ASYNC port structure */
int combase, irq, vctr; /* port address, IRQ number, & vector */
int openmask = 0; /* mask for forcing no FIFOs, no MSR intrpts */
long LocBaud = 0L; /* CPU to modem/device baud rate */
char params[12] = ""; /* port parameters */
char lockedbaud[12] = ""; /* locked baud parameter */
char fnames[256] = ""; /* list of files to send if sending */
char minsecs[10]; /* seconds to min:secs buffer */
char *color; /* pointer to list of colors */
int txtcolor; /* color of most screen message output */
char buf[256]; /* general purpose buffer */
int goodargs = 0; /* got an 'r' or an 's' on command line */
char *node = NULL; /* for bbs use: LASTUSER.BBS format file name */
int miniterm = 0; /* mini-terminal mode selected */
char OvlyIO; /* overlay disk and serial I/O flag */
char *flist; /* used when expanding subdirectories */
char mask[14]; /* used when expanding subdirectories */
int plen; /* used when expanding subdirectories */
int tryDV = 0; /* cmdline switch to test for DesqView */
int checkcarrier = 0; /* check for carrier during 'waitfor' flag */
int stripmask = 0xff; /* strip high bit mask for miniterm mode */
char phone[40] = ""; /* phone number to dial */
char DialPrefix[16] = "ATDT"; /* default dial prefix */
char *OverrideName = NULL; /* cmdline rx filename used if not NULL */
char OverrideFlag = '\0'; /* if '/', above specifies complete pathname */
long PrevSecs = -1L; /* used by getSeconds to handle midnight */
long PrevHunds = -1L; /* used by getHunds to handle midnight */
long tfBytes, tCPS; /* total bytes transferred, average CPS */
int tFiles; /* number of files transferred */
/* variables & dummy function to disable display of file transfer screen */
int qf = 0;
void DoNothing(int r, int c, int a, char *s) {}
void (*DspMsgAt[2])(int, int, int, char *) = { d_msgat, DoNothing };
/*/////////////////////////////////////////////////////////
// //
// Main //
// //
//:mai////////////////////////////////////////////////// */
void cdecl main(int argc, char *argv[])
{
int i, FIFOretry = 0;
color = ((initvid() & 0xff) == CO80) ? cfg.Color : cfg.Mono;
txtcolor = (int)color[1] & 0xff;
InitDefaults();
ProcCmdLine(argc, argv);
if (!goodargs)
usage();
if (tryDV && TestDesqView() != 0)
{
i = DV_VideoSeg(v_seg);
if (v_seg != i)
v_seg = i, v_snow = 0;
}
if (*params)
ConnectBaud = atol(params);
if (*lockedbaud)
LocBaud = atol(lockedbaud);
if (LocBaud == 0L)
LocBaud = ConnectBaud;
if (LocBaud != 0L)
{
sprintf(params, "%ldN81", LocBaud);
if (LocBaud < cfg.MinFifoBaud)
openmask |= 0x4000;
}
if (OvlyIO)
VBufSize = cfg.h_VBufSize, BufSize = cfg.h_BufSize;
else
VBufSize = cfg.b_VBufSize, BufSize = cfg.b_BufSize;
if (BufSize)
ZFR0 &= ~CANOVIO;
AllocRingBuffer(&port, 2048, 4096, 0);
tickhookset(1);
while (1)
{
i = async_open(&port, combase, irq, vctr|openmask, params);
if (i != 0)
{
if (i == 512 && (port.Stat3 & B_FIFO) && FIFOretry == 0
&& !(openmask & 0x4000))
{
openmask |= 0x4000;
FIFOretry = 1; /* FIFO retry code fixes s